/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taglibs;

import daos.EditorialDAO;
import daos.ItemDAO;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import models.Editorial;
import models.Item;
import util.WebConst;

/**
 *
 * @author trietto
 */
public class News extends TagSupport {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /*
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
     */
    public int doStartTag() {
        try {
            JspWriter writer = pageContext.getOut();

            Editorial editorial = EditorialDAO.singleton().selectByCategory(WebConst.NEWS);
            Item item = null;
            if (editorial != null) {
                item = ItemDAO.singleton().select(editorial.getItemId());
            }

            writer.println("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
            writer.println("<tr>");
            writer.println("<td align='center'><b>NEWS</b><br></td>");
            writer.println("</tr>");
            if (editorial != null && item != null) {
                writer.println("<tr>");
                writer.println("<td><a href='BookDetail.jsp?itemid="
                        + item.getItemId() + "'>" + item.getName() + "</a></td>");
                writer.println("</tr>");
                writer.println("<tr>");
                writer.println("<td>" + editorial.getArticleDesc() + "</td>");
                writer.println("</tr>");
                writer.println("<tr>");
                writer.println("<td><img alt='' src='" + item.getImageURL() + "' /></td>");
                writer.println("</tr>");
            }
            writer.println("</table>");
        } catch (Exception e) {
        }
        return SKIP_BODY;
    }
}
